<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\SwtMarketChain;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class SwtMarketChainController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new SwtMarketChain(), function (Grid $grid) {
            $grid->model()->orderByDesc('id');

            $grid->column('id')->sortable();
            $grid->column('icon') -> image(config('app.url').'/storage', 50, 50);
            $grid->column('full_name');
            $grid->column('base_ccy');
            $grid->column('quote_ccy');
            $grid->column('lever');
            $grid->column('state') ->using(['live' =>'交易中', 'suspend'=>'暂停中'])->label(['live' =>'success', 'suspend'=>'danger']);;
            $grid->column('mark') ->using(['main' =>'主流币'])->label(['main' =>'success']);
            $grid->column('list_time');
            $grid->column('status','状态')->switch('success');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid -> disableActions();
            $grid->disableCreateButton(); //关闭新增按钮
            $grid->selector(function (Grid\Tools\Selector $selector) {
                $selector->select('status', '状态', ['禁用','启用']);
                $selector->select('mark', '标记', ['main'=>'主流币']);
            });

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->like('base_ccy');
                $filter->like('quote_ccy');
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new SwtMarketChain(), function (Show $show) {
            $show->field('id');
            $show->field('type');
            $show->field('full_name');
            $show->field('lever');
            $show->field('state');
            $show->field('mark');
            $show->field('list_time');
            $show->field('status');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new SwtMarketChain(), function (Form $form) {
            $form->display('id');
            $form->radio('status','状态') -> options([ '0' => '禁用', '2'=>'启用'])-> required();
        });
    }
}
